package com.ssmk.module.shoppingcar.presenter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.example.retrofitlibrary.BaseObserBean2;
import com.example.retrofitlibrary.RetrofitClientUtlis;
import com.ssmk.base.BasePresenter;
import com.ssmk.base.BaseView;
import com.ssmk.module.shoppingcar.bean.OrderAllBean;
import com.ssmk.url.Url;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/8 0008.
 */

public class ChackLogisticsPresenter implements BasePresenter{

    private Context mContext;
    private BaseView mBaseView;
    private String mLogisticsCode;
    private String mCourierNumber;

    //静态内部单例
    private static class SinglePresanter{
        private static ChackLogisticsPresenter instance;
        static {
            instance = new ChackLogisticsPresenter();
        }
    }
    public static ChackLogisticsPresenter getInstance() {
        return SinglePresanter.instance;
    }

    private void getPparameter(Context context, BaseView baseView,String logisticsCode,String courierNumber){
        this.mContext = context;
        this.mBaseView = baseView;
        this.mLogisticsCode = logisticsCode;
        this.mCourierNumber = courierNumber;
    }


    @Override
    public void SetDataModel(Object o) {

    }

    @Override
    public void GetDataModel() {
        Map<String, String> checkMap = new HashMap<>();//查看物流
        Map<String, String> mapHeader = new HashMap<>();
        mapHeader.put("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjI1MiwicHdkIjoiZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2UiLCJpYXQiOjE1MDA0MzYyNzg1MDIsImV4dCI6MTUwMTA0MTA3ODUwMn0.ws2972b0tfqUWbiluxEEtv_2mbAjZzk3k9lTFxyHIvA");

        if (!TextUtils.isEmpty(mLogisticsCode) && !TextUtils.isEmpty(mCourierNumber)){
            checkMap.put("LogisticsCode",mLogisticsCode);
            checkMap.put("CourierNumber",mCourierNumber);
        }
    }
    private void requestCheckLogisticsDate(Map<String, String> map, Map<String, String> mapHeader) {
        RetrofitClientUtlis.getInstance(mContext, Url.CHECKLOGISTICS, mapHeader)
                .createBaseApi()
                .post2(Url.LOGISTICS, map, new BaseObserBean2<OrderAllBean>(mContext, OrderAllBean.class) {
                    @Override
                    public void Next(OrderAllBean data) {
                        if (data != null) {
                            mBaseView.UpData(data);
                        } else {
                            Toast.makeText(mContext, "请求数据失败！", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
}
